package cn.geminis.lowcode.compiler.code;

import cn.geminis.lowcode.compiler.util.JdkTreeMakerUtils;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.VariableTree;
import lombok.RequiredArgsConstructor;

import javax.lang.model.element.VariableElement;

/**
 * @author puddi
 */
@RequiredArgsConstructor
public class LcVariable extends AbstractCode<VariableTree, VariableElement> {

    private final LcModifier modifiers;
    private final String type;
    private final String name;
    private final ExpressionTree init;
    private final boolean declareUsingVar;

    public LcVariable(LcModifier modifiers, String type, String name) {
        this(modifiers, type, name, null, false);
    }

    @Override
    protected VariableTree createJdkTree() {
        return JdkTreeMakerUtils.variableDef(
                this.modifiers.getJdkTree(),
                type,
                name,
                init,
                declareUsingVar
        );
    }

    @Override
    protected VariableElement createJdkElement() {
        throw new UnsupportedOperationException();
    }
}
